/**
 * Copyright  2025, Hai Yue Xing He  ZHAO LIMIN
 *
 * @author        ZHAO LIMIN
 * @version       1.0.1
 * @since         2025-04
 * HYXHDefaultValue.ts 默认值处理
 */
/**
 * Returns the first parameter if not undefined, otherwise the second parameter.
 * Useful for setting a default value for a parameter.
 *
 * @function
 *
 * @param {*} a
 * @param {*} b
 * @returns {*} Returns the first parameter if not undefined, otherwise the second parameter.
 *
 * @example
 * param = defaultValue(param, 'default');
 */
export function defaultValue<T>(a: T | undefined, b: T): T {
  if (a !== undefined && a !== null) {
    return a
  }
  return b
}

/**
 * A frozen empty object that can be used as the default value for options passed as
 * an object literal.
 * @type {object}
 * @memberof defaultValue
 */
defaultValue.EMPTY_OBJECT = Object.freeze({})
